package com.neusoft.restaurant.service.impl;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.neusoft.restaurant.config.utils.PageUtils;
import com.neusoft.restaurant.entity.PageResult;
import com.neusoft.restaurant.entity.ResCollect;
import com.neusoft.restaurant.mapper.ResCollectMapper;
import com.neusoft.restaurant.service.IResCollectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 收藏Service业务层处理
 *
 * @author zhongda
 * @date 2023-12-09
 */
@Service
public class ResCollectServiceImpl implements IResCollectService {
    @Autowired
    private ResCollectMapper resCollectMapper;

    /**
     * 查询收藏
     *
     * @param id 收藏主键
     * @return 收藏
     */
    @Override
    public ResCollect selectResCollectById(Long id) {
        return resCollectMapper.selectResCollectById(id);
    }

    /**
     * 查询收藏列表
     *
     * @param resCollect 收藏
     * @return 收藏
     */
    @Override
    public List<ResCollect> selectResCollectList(ResCollect resCollect) {
        return resCollectMapper.selectResCollectList(resCollect);
    }

    /**
     * 分页查询收藏列表
     *
     * @param resCollect 收藏
     * @return 收藏
     */
    @Override
    public PageResult selectResCollectList2(ResCollect resCollect, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<ResCollect> resCollects = resCollectMapper.selectResCollectList(resCollect);
        if (resCollects.size()==0){
            return null;
        }
        PageInfo<ResCollect> resCollectPageInfo = new PageInfo<>(resCollects);
        PageResult pageResult = PageUtils.getPageResult(resCollectPageInfo);

        return pageResult;
    }

    /**
     * 新增收藏
     *
     * @param resCollect 收藏
     * @return 结果
     */
    @Override
    public int insertResCollect(ResCollect resCollect) {
        resCollect.setCreateTime(new Date());
        return resCollectMapper.insertResCollect(resCollect);
    }

    /**
     * 修改收藏
     *
     * @param resCollect 收藏
     * @return 结果
     */
    @Override
    public int updateResCollect(ResCollect resCollect) {
        return resCollectMapper.updateResCollect(resCollect);
    }

    /**
     * 批量删除收藏
     *
     * @param ids 需要删除的收藏主键
     * @return 结果
     */
    @Override
    public int deleteResCollectByIds(Long[] ids) {
        return resCollectMapper.deleteResCollectByIds(ids);
    }

    /**
     * 删除收藏信息
     *
     * @param id 收藏主键
     * @return 结果
     */
    @Override
    public int deleteResCollectById(Long id) {
        return resCollectMapper.deleteResCollectById(id);
    }
}
